﻿Imports Microsoft.Msdn.Samples.BITS

Module ModBITS
    Public BITS As New Manager()

    ''' <summary>
    ''' Checks if a job is in state transferred
    ''' </summary>
    ''' <param name="JobNumber">Number of the job in the list of all jobs</param>
    ''' <returns>Returns if the job provieded is transferred</returns>
    ''' <remarks></remarks>
    Public Function _JobFinished(ByVal JobNumber As Integer) As Boolean
        Dim Jobs As JobCollection
        Dim Job As Job

        Jobs = BITS.GetListofJobs
        Job = Jobs(JobNumber)
        If Job.State = JobState.Transferred Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function _FinishJob(ByVal JobNumber As Integer) As Boolean
        Dim Job As Job
        Dim Jobs As JobCollection
        Jobs = BITS.GetListofJobs
        Job = Jobs(JobNumber)
        Try
            Job.Complete()
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function _ResumeJob(ByVal JobNumber As Integer) As Boolean
        Dim Job As Job
        Dim Jobs As JobCollection

        Try
            Jobs = BITS.GetListofJobs
            Job = Jobs(JobNumber)
            Job.ResumeJob()
            Return True
        Catch ex As Exception
            Return False
            MsgBox(ex.ToString)
        End Try
    End Function

    Public Function _SuspendJob(ByVal JobNumber As Integer) As Boolean
        Dim Job As Job
        Dim Jobs As JobCollection

        Try
            Jobs = BITS.GetListofJobs
            Job = Jobs(JobNumber)
            Job.Suspend()
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Sub _Reload()
        BITS = Nothing
        BITS = New Manager()
    End Sub
End Module
